package com.neuronbit.businessflow.intellij.psi;

import com.neuronbit.businessflow.intellij.BpmIcons;
import com.intellij.codeInsight.daemon.RelatedItemLineMarkerInfo;
import com.intellij.codeInsight.daemon.RelatedItemLineMarkerProvider;
import com.intellij.codeInsight.navigation.NavigationGutterIconBuilder;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiIdentifier;
import com.intellij.psi.PsiMethod;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * The type Simple line marker provider.
 */
public class SimpleLineMarkerProvider extends RelatedItemLineMarkerProvider {
    @Override
    protected void collectNavigationMarkers(@NotNull PsiElement element,
                                            @NotNull Collection<? super RelatedItemLineMarkerInfo<?>> result) {
        // This must be an element with a literal expression as a parent
        if (!(element instanceof PsiIdentifier) || !(element.getParent() instanceof PsiMethod)) {
            return;
        }

        // The literal expression must start with the Simple language literal expression
        String value = ((PsiIdentifier) element).getText();

        // Get the Simple language property usage
        Project project = element.getProject();

        final List<PsiElement> properties = new ArrayList<>();
        if (properties.size() > 0) {
            // Add the property to a collection of line marker info
            NavigationGutterIconBuilder<PsiElement> builder =
                    NavigationGutterIconBuilder.create(BpmIcons.FLOW_ICON)
                            .setTargets(properties)
                            .setTooltipText("Navigate to Simple language property");
            result.add(builder.createLineMarkerInfo(element));
        }
    }
}
